home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 2 / Amiga Tools 2.iso / tools / packer / gnu-tar / getdate.y < prev    next >
Text File  |  1995-03-09  |  14KB  |  630 lines

  1. %token ID MONTH DAY MERIDIAN NUMBER UNIT MUNIT SUNIT ZONE DAYZONE AGO DST
  2. %{
  3.     /*     Originally from: Steven M. Bellovin (unc!smb)    */ 
  4.     /*    Dept. of Computer Science            */
  5.     /*    University of North Carolina at Chapel Hill    */
  6.     /*    @(#)getdate.y    2.17    11/30/87            */
  7.  
  8. /* #include "defs.h" JF not used any more */
  9. #include <sys/types.h>
  10. #ifdef USG
  11. struct timeb
  12. {
  13.     time_t    time;
  14.     unsigned short millitm;
  15.     short    timezone;
  16.     short    dstflag;
  17. };
  18. static void ftime ();
  19. #else
  20. #include <sys/timeb.h>
  21. #endif
  22. #include <ctype.h>
  23.  
  24. #if defined(BSD4_2) || defined (BSD4_1C)
  25. #include <sys/time.h>
  26. #else /* sane */
  27. #include <time.h>
  28. #endif /* sane */
  29.  
  30. #if defined (STDC_HEADERS) || defined (USG)
  31. #include <string.h>
  32. #endif
  33.  
  34. #ifdef __GNUC__
  35. #define alloca __builtin_alloca
  36. #else
  37. #ifdef sparc
  38. #include <alloca.h>
  39. #endif
  40. #endif
  41.  
  42. #ifndef NULL
  43. #define    NULL    0
  44. #endif
  45. #define daysec (24L*60L*60L)
  46.     static int timeflag, zoneflag, dateflag, dayflag, relflag;
  47.     static time_t relsec, relmonth;
  48.     static int hh, mm, ss, merid, day_light;
  49.     static int dayord, dayreq;
  50.     static int month, day, year;
  51.     static int ourzone;
  52. #define AM 1
  53. #define PM 2
  54. #define DAYLIGHT 1
  55. #define STANDARD 2
  56. #define MAYBE    3
  57.  
  58. static time_t timeconv();
  59. static time_t daylcorr();
  60. static lookup();
  61.  
  62. static int yylex ();
  63. #define yyparse getdate_yyparse
  64. static int yyerror ();
  65.  
  66. %}
  67.  
  68. %%
  69. timedate:         /* empty */
  70.     | timedate item
  71.     ;
  72.  
  73. item:    tspec
  74.         {timeflag++;}
  75.     | zone
  76.         {zoneflag++;}
  77.     | dtspec
  78.         {dateflag++;}
  79.     | dyspec
  80.         {dayflag++;}
  81.     | rspec
  82.         {relflag++;}
  83.     | nspec;
  84.  
  85. nspec:    NUMBER
  86.         {if (timeflag && dateflag && !relflag) year = $1;
  87.         else if ($1 > 10000) {
  88.             dateflag++;
  89.             day= $1%100;
  90.             month= ($1/100)%100;
  91.             year = month/10000;
  92.         } else {timeflag++;hh = $1/100;mm = $1%100;ss = 0;merid = 24;}};
  93.  
  94. tspec:    NUMBER MERIDIAN
  95.         {hh = $1; mm = 0; ss = 0; merid = $2;}
  96.     | NUMBER ':' NUMBER
  97.         {hh = $1; mm = $3; merid = 24;}
  98.     | NUMBER ':' NUMBER MERIDIAN
  99.         {hh = $1; mm = $3; merid = $4;}
  100.     | NUMBER ':' NUMBER NUMBER
  101.         {hh = $1; mm = $3; merid = 24;
  102.         day_light = STANDARD; ourzone = -($4%100 + 60*($4/100));}
  103.     | NUMBER ':' NUMBER ':' NUMBER
  104.         {hh = $1; mm = $3; ss = $5; merid = 24;}
  105.     | NUMBER ':' NUMBER ':' NUMBER MERIDIAN
  106.         {hh = $1; mm = $3; ss = $5; merid = $6;}
  107.     | NUMBER ':' NUMBER ':' NUMBER NUMBER
  108.         {hh = $1; mm = $3; ss = $5; merid = 24;
  109.         day_light = STANDARD; ourzone = -($6%100 + 60*($6/100));};
  110.  
  111. zone:    ZONE dst
  112.         {ourzone = $1; day_light = $2;}
  113.     | DAYZONE
  114.         {ourzone = $1; day_light = DAYLIGHT;};
  115.  
  116. dst:    /* empty */
  117.         { $$ = STANDARD; }
  118.     | DST
  119.         { $$ = DAYLIGHT; };
  120.  
  121. dyspec:    DAY
  122.         {dayord = 1; dayreq = $1;}
  123.     | DAY ','
  124.         {dayord = 1; dayreq = $1;}
  125.     | NUMBER DAY
  126.         {dayord = $1; dayreq = $2;};
  127.  
  128. dtspec:    NUMBER '/' NUMBER
  129.         {month = $1; day = $3;}
  130.     | NUMBER '/' NUMBER '/' NUMBER
  131.         {month = $1; day = $3; year = $5;}
  132.     | MONTH NUMBER
  133.         {month = $1; day = $2;}
  134.     | MONTH NUMBER ',' NUMBER
  135.         {month = $1; day = $2; year = $4;}
  136.     | NUMBER MONTH
  137.         {month = $2; day = $1;}
  138.     | NUMBER MONTH NUMBER
  139.         {month = $2; day = $1; year = $3;};
  140.  
  141.  
  142. rspec:    NUMBER UNIT
  143.         {relsec +=  60L * $1 * $2;}
  144.     | NUMBER MUNIT
  145.         {relmonth += $1 * $2;}
  146.     | NUMBER SUNIT
  147.         {relsec += $1;}
  148.     | UNIT
  149.         {relsec +=  60L * $1;}
  150.     | MUNIT
  151.         {relmonth += $1;}
  152.     | SUNIT
  153.         {relsec++;}
  154.     | rspec AGO
  155.         {relsec = -relsec; relmonth = -relmonth;};
  156. %%
  157.  
  158. static int mdays[12] =
  159.     {31, 0, 31,  30, 31, 30,  31, 31, 30,  31, 30, 31};
  160. #define epoch 1970
  161.  
  162. extern struct tm *localtime();
  163.  
  164. static time_t
  165. dateconv(mm, dd, yy, h, m, s, mer, zone, dayflag)
  166. int mm, dd, yy, h, m, s, mer, zone, dayflag;
  167. {
  168.     time_t tod, jdate;
  169.     register int i;
  170.  
  171.     if (yy < 0) yy = -yy;
  172.     if (yy < 100) yy += 1900;
  173.     mdays[1] = 28 + (yy%4 == 0 && (yy%100 != 0 || yy%400 == 0));
  174.     if (yy < epoch || yy > 1999 || mm < 1 || mm > 12 ||
  175.         dd < 1 || dd > mdays[--mm]) return (-1);
  176.     jdate = dd-1;
  177.         for (i=0; i<mm; i++) jdate += mdays[i];
  178.     for (i = epoch; i < yy; i++) jdate += 365 + (i%4 == 0);
  179.     jdate *= daysec;
  180.     jdate += zone * 60L;
  181.     if ((tod = timeconv(h, m, s, mer)) < 0) return (-1);
  182.     jdate += tod;
  183.     if (dayflag==DAYLIGHT || (dayflag==MAYBE&&localtime(&jdate)->tm_isdst))
  184.         jdate += -1*60*60;
  185.     return (jdate);
  186. }
  187.  
  188. static time_t
  189. dayconv(ord, day, now)
  190. int ord, day; time_t now;
  191. {
  192.     register struct tm *loctime;
  193.     time_t tod;
  194.  
  195.     tod = now;
  196.     loctime = localtime(&tod);
  197.     tod += daysec * ((day - loctime->tm_wday + 7) % 7);
  198.     tod += 7*daysec*(ord<=0?ord:ord-1);
  199.     return daylcorr(tod, now);
  200. }
  201.  
  202. static time_t
  203. timeconv(hh, mm, ss, mer)
  204. register int hh, mm, ss, mer;
  205. {
  206.     if (mm < 0 || mm > 59 || ss < 0 || ss > 59) return (-1);
  207.     switch (mer) {
  208.         case AM: if (hh < 1 || hh > 12) return(-1);
  209.              return (60L * ((hh%12)*60L + mm)+ss);
  210.         case PM: if (hh < 1 || hh > 12) return(-1);
  211.              return (60L * ((hh%12 +12)*60L + mm)+ss);
  212.         case 24: if (hh < 0 || hh > 23) return (-1);
  213.              return (60L * (hh*60L + mm)+ss);
  214.         default: return (-1);
  215.     }
  216. }
  217.  
  218. static time_t
  219. monthadd(sdate, relmonth)
  220. time_t sdate, relmonth;
  221. {
  222.     struct tm *ltime;
  223.     time_t dateconv();
  224.     int mm, yy;
  225.  
  226.     if (relmonth == 0) return 0;
  227.     ltime = localtime(&sdate);
  228.     mm = 12*ltime->tm_year + ltime->tm_mon + relmonth;
  229.     yy = mm/12;
  230.     mm = mm%12 + 1;
  231.     return daylcorr(dateconv(mm, ltime->tm_mday, yy, ltime->tm_hour,
  232.         ltime->tm_min, ltime->tm_sec, 24, ourzone, MAYBE), sdate);
  233. }
  234.  
  235. static time_t
  236. daylcorr(future, now)
  237. time_t future, now;
  238. {
  239.     int fdayl, nowdayl;
  240.  
  241.     nowdayl = (localtime(&now)->tm_hour+1) % 24;
  242.     fdayl = (localtime(&future)->tm_hour+1) % 24;
  243.     return (future-now) + 60L*60L*(nowdayl-fdayl);
  244. }
  245.  
  246. static char *lptr;
  247.  
  248. static int
  249. yylex()
  250. {
  251.     extern int yylval;
  252.     int sign;
  253.     register char c;
  254.     register char *p;
  255.     char idbuf[20];
  256.     int pcnt;
  257.  
  258.     for (;;) {
  259.         while (isspace(*lptr))
  260.             lptr++;
  261.  
  262.         if (isdigit(c = *lptr) || c == '-' || c == '+') {
  263.             if (c== '-' || c == '+') {
  264.                 if (c=='-') sign = -1;
  265.                 else sign = 1;
  266.                 if (!isdigit(*++lptr)) {
  267.                     /* yylval = sign; return (NUMBER); */
  268.                     return yylex();    /* skip the '-' sign */
  269.                 }
  270.             } else sign = 1;
  271.             yylval = 0;
  272.             while (isdigit(c = *lptr++))
  273.                 yylval = 10*yylval + c - '0';
  274.             yylval *= sign;
  275.             lptr--;
  276.             return (NUMBER);
  277.  
  278.         } else if (isalpha(c)) {
  279.             p = idbuf;
  280.             while (isalpha(c = *lptr++) || c=='.')
  281.                 if (p < &idbuf[sizeof(idbuf)-1]) *p++ = c;
  282.             *p = '\0';
  283.             lptr--;
  284.             return (lookup(idbuf));
  285.         }
  286.  
  287.         else if (c == '(') {
  288.             pcnt = 0;
  289.             do {
  290.                 c = *lptr++;
  291.                 if (c == '\0') return(c);
  292.                 else if (c == '(') pcnt++;
  293.                 else if (c == ')') pcnt--;
  294.             } while (pcnt > 0);
  295.         }
  296.  
  297.         else return (*lptr++);
  298.     }
  299. }
  300.  
  301. struct table {
  302.     char *name;
  303.     int type, value;
  304. };
  305.  
  306. static struct table mdtab[] = {
  307.     {"january", MONTH, 1},
  308.     {"february", MONTH, 2},
  309.     {"march", MONTH, 3},
  310.     {"april", MONTH, 4},
  311.     {"may", MONTH, 5},
  312.     {"june", MONTH, 6},
  313.     {"july", MONTH, 7},
  314.     {"august", MONTH, 8},
  315.     {"september", MONTH, 9},
  316.     {"sept", MONTH, 9},
  317.     {"october", MONTH, 10},
  318.     {"november", MONTH, 11},
  319.     {"december", MONTH, 12},
  320.  
  321.     {"sunday", DAY, 0},
  322.     {"monday", DAY, 1},
  323.     {"tuesday", DAY, 2},
  324.     {"tues", DAY, 2},
  325.     {"wednesday", DAY, 3},
  326.     {"wednes", DAY, 3},
  327.     {"thursday", DAY, 4},
  328.     {"thur", DAY, 4},
  329.     {"thurs", DAY, 4},
  330.     {"friday", DAY, 5},
  331.     {"saturday", DAY, 6},
  332.     {0, 0, 0}
  333. };
  334.  
  335. #define HRS *60
  336. #define HALFHR 30
  337.  
  338. static struct table mztab[] = {
  339.     {"a.m.", MERIDIAN, AM},
  340.     {"am", MERIDIAN, AM},
  341.     {"p.m.", MERIDIAN, PM},
  342.     {"pm", MERIDIAN, PM},
  343.     {"nst", ZONE, 3 HRS + HALFHR},        /* Newfoundland */
  344.     {"n.s.t.", ZONE, 3 HRS + HALFHR},
  345.     {"ast", ZONE, 4 HRS},        /* Atlantic */
  346.     {"a.s.t.", ZONE, 4 HRS},
  347.     {"adt", DAYZONE, 4 HRS},
  348.     {"a.d.t.", DAYZONE, 4 HRS},
  349.     {"est", ZONE, 5 HRS},        /* Eastern */
  350.     {"e.s.t.", ZONE, 5 HRS},
  351.     {"edt", DAYZONE, 5 HRS},
  352.     {"e.d.t.", DAYZONE, 5 HRS},
  353.     {"cst", ZONE, 6 HRS},        /* Central */
  354.     {"c.s.t.", ZONE, 6 HRS},
  355.     {"cdt", DAYZONE, 6 HRS},
  356.     {"c.d.t.", DAYZONE, 6 HRS},
  357.     {"mst", ZONE, 7 HRS},        /* Mountain */
  358.     {"m.s.t.", ZONE, 7 HRS},
  359.     {"mdt", DAYZONE, 7 HRS},
  360.     {"m.d.t.", DAYZONE, 7 HRS},
  361.     {"pst", ZONE, 8 HRS},        /* Pacific */
  362.     {"p.s.t.", ZONE, 8 HRS},
  363.     {"pdt", DAYZONE, 8 HRS},
  364.     {"p.d.t.", DAYZONE, 8 HRS},
  365.     {"yst", ZONE, 9 HRS},        /* Yukon */
  366.     {"y.s.t.", ZONE, 9 HRS},
  367.     {"ydt", DAYZONE, 9 HRS},
  368.     {"y.d.t.", DAYZONE, 9 HRS},
  369.     {"hst", ZONE, 10 HRS},        /* Hawaii */
  370.     {"h.s.t.", ZONE, 10 HRS},
  371.     {"hdt", DAYZONE, 10 HRS},
  372.     {"h.d.t.", DAYZONE, 10 HRS},
  373.  
  374.     {"gmt", ZONE, 0 HRS},
  375.     {"g.m.t.", ZONE, 0 HRS},
  376.     {"bst", DAYZONE, 0 HRS},        /* British Summer Time */
  377.     {"b.s.t.", DAYZONE, 0 HRS},
  378.     {"eet", ZONE, 0 HRS},        /* European Eastern Time */
  379.     {"e.e.t.", ZONE, 0 HRS},
  380.     {"eest", DAYZONE, 0 HRS},    /* European Eastern Summer Time */
  381.     {"e.e.s.t.", DAYZONE, 0 HRS},
  382.     {"met", ZONE, -1 HRS},        /* Middle European Time */
  383.     {"m.e.t.", ZONE, -1 HRS},
  384.     {"mest", DAYZONE, -1 HRS},    /* Middle European Summer Time */
  385.     {"m.e.s.t.", DAYZONE, -1 HRS},
  386.     {"wet", ZONE, -2 HRS },        /* Western European Time */
  387.     {"w.e.t.", ZONE, -2 HRS },
  388.     {"west", DAYZONE, -2 HRS},    /* Western European Summer Time */
  389.     {"w.e.s.t.", DAYZONE, -2 HRS},
  390.  
  391.     {"jst", ZONE, -9 HRS},        /* Japan Standard Time */
  392.     {"j.s.t.", ZONE, -9 HRS},    /* Japan Standard Time */
  393.                     /* No daylight savings time */
  394.  
  395.     {"aest", ZONE, -10 HRS},    /* Australian Eastern Time */
  396.     {"a.e.s.t.", ZONE, -10 HRS},
  397.     {"aesst", DAYZONE, -10 HRS},    /* Australian Eastern Summer Time */
  398.     {"a.e.s.s.t.", DAYZONE, -10 HRS},
  399.     {"acst", ZONE, -(9 HRS + HALFHR)},    /* Australian Central Time */
  400.     {"a.c.s.t.", ZONE, -(9 HRS + HALFHR)},
  401.     {"acsst", DAYZONE, -(9 HRS + HALFHR)},    /* Australian Central Summer */
  402.     {"a.c.s.s.t.", DAYZONE, -(9 HRS + HALFHR)},
  403.     {"awst", ZONE, -8 HRS},        /* Australian Western Time */
  404.     {"a.w.s.t.", ZONE, -8 HRS},    /* (no daylight time there, I'm told */
  405.     {"dst", DST, 0},        /* Explicit daylight time */
  406.     {0, 0, 0}};
  407.  
  408. static struct table unittb[] = {
  409.     {"year", MUNIT, 12},
  410.     {"month", MUNIT, 1},
  411.     {"fortnight", UNIT, 14*24*60},
  412.     {"week", UNIT, 7*24*60},
  413.     {"day", UNIT, 1*24*60},
  414.     {"hour", UNIT, 60},
  415.     {"minute", UNIT, 1},
  416.     {"min", UNIT, 1},
  417.     {"second", SUNIT, 1},
  418.     {"sec", SUNIT, 1},
  419.     {0, 0, 0}};
  420.  
  421. static struct table othertb[] = {
  422.     {"tomorrow", UNIT, 1*24*60},
  423.     {"yesterday", UNIT, -1*24*60},
  424.     {"today", UNIT, 0},
  425.     {"now", UNIT, 0},
  426.     {"last", NUMBER, -1},
  427.     {"this", UNIT, 0},
  428.     {"next", NUMBER, 2},
  429.     {"first", NUMBER, 1},
  430.     /* {"second", NUMBER, 2}, */
  431.     {"third", NUMBER, 3},
  432.     {"fourth", NUMBER, 4},
  433.     {"fifth", NUMBER, 5},
  434.     {"sixth", NUMBER, 6},
  435.     {"seventh", NUMBER, 7},
  436.     {"eigth", NUMBER, 8},
  437.     {"ninth", NUMBER, 9},
  438.     {"tenth", NUMBER, 10},
  439.     {"eleventh", NUMBER, 11},
  440.     {"twelfth", NUMBER, 12},
  441.     {"ago", AGO, 1},
  442.     {0, 0, 0}};
  443.  
  444. static struct table milzone[] = {
  445.     {"a", ZONE, 1 HRS},
  446.     {"b", ZONE, 2 HRS},
  447.     {"c", ZONE, 3 HRS},
  448.     {"d", ZONE, 4 HRS},
  449.     {"e", ZONE, 5 HRS},
  450.     {"f", ZONE, 6 HRS},
  451.     {"g", ZONE, 7 HRS},
  452.     {"h", ZONE, 8 HRS},
  453.     {"i", ZONE, 9 HRS},
  454.     {"k", ZONE, 10 HRS},
  455.     {"l", ZONE, 11 HRS},
  456.     {"m", ZONE, 12 HRS},
  457.     {"n", ZONE, -1 HRS},
  458.     {"o", ZONE, -2 HRS},
  459.     {"p", ZONE, -3 HRS},
  460.     {"q", ZONE, -4 HRS},
  461.     {"r", ZONE, -5 HRS},
  462.     {"s", ZONE, -6 HRS},
  463.     {"t", ZONE, -7 HRS},
  464.     {"u", ZONE, -8 HRS},
  465.     {"v", ZONE, -9 HRS},
  466.     {"w", ZONE, -10 HRS},
  467.     {"x", ZONE, -11 HRS},
  468.     {"y", ZONE, -12 HRS},
  469.     {"z", ZONE, 0 HRS},
  470.     {0, 0, 0}};
  471.  
  472. static int
  473. lookup(id)
  474. char *id;
  475. {
  476. #define gotit (yylval=i->value,  i->type)
  477.  
  478.     char idvar[128];
  479.     register char *j, *k;
  480.     register struct table *i;
  481.     int abbrev;
  482.  
  483.     (void) strcpy(idvar, id);
  484.     j = idvar;
  485.     k = id - 1;
  486.     while (*++k)
  487.         *j++ = isupper(*k) ? tolower(*k) : *k;
  488.     *j = '\0';
  489.  
  490.     if (strlen(idvar) == 3)
  491.         abbrev = 1;
  492.     else
  493.         if (strlen(idvar) == 4 && idvar[3] == '.' && idvar[1] != '.') {
  494.             abbrev = 1;
  495.             idvar[3] = '\0';
  496.         }
  497.     else
  498.         abbrev = 0;
  499.  
  500.     for (i = mdtab; i->name; i++) {
  501.         k = idvar;
  502.         for (j = i->name; *j++ == *k++;) {
  503.             if (abbrev && j == i->name+3)
  504.                 return gotit;
  505.             if (j[-1] == 0)
  506.                 return gotit;
  507.         }
  508.     }
  509.  
  510.     for (i=mztab; i->name; i++)
  511.         if (strcmp(i->name, idvar) == 0)
  512.             return gotit;
  513.  
  514.     for (i=unittb; i->name; i++)
  515.         if (strcmp(i->name, idvar) == 0)
  516.             return gotit;
  517.  
  518.     if (idvar[strlen(idvar)-1] == 's')
  519.         idvar[strlen(idvar)-1] = '\0';
  520.  
  521.     for (i=unittb; i->name; i++)
  522.         if (strcmp(i->name, idvar) == 0)
  523.             return gotit;
  524.  
  525.     for (i = othertb; i->name; i++)
  526.         if (strcmp(i->name, idvar) == 0)
  527.             return gotit;
  528.  
  529.     if (strlen(idvar) == 1 && isalpha(*idvar)) {
  530.         for (i = milzone; i->name; i++)
  531.             if (strcmp(i->name, idvar) == 0)
  532.                 return gotit;
  533.     }
  534.  
  535.     return ID;
  536. }
  537.  
  538. time_t
  539. getdate(p, now)
  540. char *p;
  541. struct timeb *now;
  542. {
  543. #define mcheck(f)    if (f>1) err++
  544.     time_t monthadd();
  545.     int err;
  546.     struct tm *lt;
  547.     struct timeb ftz;
  548.  
  549.     time_t sdate, tod;
  550.  
  551.     lptr = p;
  552.     if (now == ((struct timeb *) NULL)) {
  553.         now = &ftz;
  554.         ftime(&ftz);
  555.     }
  556.     lt = localtime(&now->time);
  557.     year = lt->tm_year;
  558.     month = lt->tm_mon+1;
  559.     day = lt->tm_mday;
  560.     relsec = 0; relmonth = 0;
  561.     timeflag=zoneflag=dateflag=dayflag=relflag=0;
  562.     ourzone = now->timezone;
  563.     day_light = MAYBE;
  564.     hh = mm = ss = 0;
  565.     merid = 24;
  566.  
  567.     if (err = yyparse()) return (-1);
  568.  
  569.     mcheck(timeflag);
  570.     mcheck(zoneflag);
  571.     mcheck(dateflag);
  572.     mcheck(dayflag);
  573.  
  574.     if (err) return (-1);
  575.     if (dateflag || timeflag || dayflag) {
  576.         sdate = dateconv(month,day,year,hh,mm,ss,merid,ourzone,day_light);
  577.         if (sdate < 0) return -1;
  578.     }
  579.     else {
  580.         sdate = now->time;
  581.         if (relflag == 0)
  582.             sdate -= (lt->tm_sec + lt->tm_min*60 +
  583.                 lt->tm_hour*(60L*60L));
  584.     }
  585.  
  586.     sdate += relsec;
  587.     sdate += monthadd(sdate, relmonth);
  588.  
  589.     if (dayflag && !dateflag) {
  590.         tod = dayconv(dayord, dayreq, sdate);
  591.         sdate += tod;
  592.     }
  593.  
  594.     /*
  595.     ** Have to do *something* with a legitimate -1 so it's distinguishable
  596.     ** from the error return value.  (Alternately could set errno on error.)
  597.     */
  598.     return (sdate == -1) ? 0 : sdate;
  599. }
  600.  
  601. static int
  602. yyerror(s)
  603. char *s;
  604. {
  605.   return 0;
  606. }
  607.  
  608. #ifdef USG
  609. static void
  610. ftime(timeb)
  611. struct timeb *timeb;
  612. {
  613.     extern long timezone;
  614. #ifndef DAYLIGHT_MISSING    /* Not all non-BSD libraries have `daylight'. */
  615.     extern int daylight;
  616. #endif
  617.     long t = 0;
  618.  
  619.     localtime(&t);    /* Dummy to init timzeone */
  620.     time(&(timeb->time));
  621.     timeb->millitm=0;
  622.     timeb->timezone=timezone/60;    /* Timezone is in seconds! */
  623. #ifndef DAYLIGHT_MISSING
  624.     timeb->dstflag=daylight;
  625. #else
  626.     timeb->dstflag=0;
  627. #endif
  628. }
  629. #endif
  630.